<template>
  <div id="banner">
    <animatedBanner
      v-if="animatedBannerEnabled"
      :config="position"
      @change="(v) => (animatedBannerShow = v)"
      :style="animatedBannerShow ? '' : `background-image: url(${bannerImg})`"
      :class="animatedBannerShow ? '' : 'staticImg'"
    />
  </div>
</template>

<script>
import animatedBanner from "./common/animatedBanner.vue";
import position from "./common/position";

export default {
  name: "FooterBanner",
  data() {
    return {
      position,
      animatedBannerShow: false,
      animatedBannerEnabled: false,
    };
  },
  components: {
    animatedBanner,
  },
  computed: {
    bannerImg() {
      return require("@/assets/images/footer_banner/static.png");
    },
  },
  methods: {
    async animatedBanner() {
      // 优先加载展示静态banner
      const staticBannerImg = document.createElement("img");
      staticBannerImg.src = this.bannerImg;
      await new Promise((resolve) => (staticBannerImg.onload = resolve()));
      this.animatedBannerEnabled = true;
      // 获取动画配置
      // try {
      //   this.animatedBannerConfig = this.position
      // this.animatedBannerEnabled = true
      // } catch (e) {
      //   console.error('animated_banner_config parse error')
      //   this.animatedBannerEnabled = false
      // }
    },
  },
  mounted() {
    this.animatedBanner();
  },
};
</script>

<style lang="less" scoped>
#banner {
  margin: 0 auto;
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 0;
  // min-height: 155px;
  min-height: 200px;
  height: 9.375vw;
  min-width: 999px;
  background-color: #f9f9f9;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-pack: center;
  justify-content: center;
  background-repeat: no-repeat;
  background-position: center 0;
  background-size: cover;
  width: 100%;
}
.staticImg {
  margin: 0 auto;
  z-index: 0;
  // min-height: 155px;
  min-height: 200px;
  height: 9.375vw;
  min-width: 999px;
  background-color: #f9f9f9;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-pack: center;
  justify-content: center;
  background-repeat: no-repeat;
  background-position: center 0;
  background-size: cover;
}
</style>
